package com.amqp.demo;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.util.JsonParserSequence;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.tools.json.JSONUtil;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
import org.springframework.amqp.ImmediateAcknowledgeAmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

public class ReceiveMsgHandler3 implements MessageListener {


        @Override
        public void onMessage(Message message) {
            String s = new String(message.getBody());
            ObjectMapper mapper = new ObjectMapper();
            // java对象转换为json字符换
            //String Json =  mapper.writeValueAsString(student1);
            // json字符串转换为java对象
            Order order = null;
            try {
                order = mapper.readValue(s, Order.class);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }

            if(order.getName().equals("1")){
                throw new RuntimeException("测试正常异常");
            }
            if(order.getName().equals("2")){
                throw new AmqpRejectAndDontRequeueException("测试拒绝异常");
            }
            if(order.getName().equals("3")){
                throw new ImmediateAcknowledgeAmqpException("测试确认异常");
            }
        }

}
